package com.qding.park.common.utils.csv;

import com.univocity.parsers.common.input.CharInputReader;
import com.univocity.parsers.common.input.DefaultCharInputReader;
import com.univocity.parsers.common.input.concurrent.ConcurrentCharInputReader;
import com.univocity.parsers.csv.CsvFormat;
import com.univocity.parsers.csv.CsvParserSettings;

public class MyCsvParserSettings extends CsvParserSettings {

    @Override
    protected CsvFormat createDefaultFormat() {
        return new MyCsvFormat();
    }

    public CharInputReader newCharInputReader() {
        return new ConcurrentCharInputReader(getFormat().getLineSeparator(), getFormat().getNormalizedNewline(),
                this.getInputBufferSize(), 10);
    }
    
    public void setLineSeparator(char[] lineSeparator) {
        if (lineSeparator == null || lineSeparator.length == 0) {
            throw new IllegalArgumentException("Invalid line separator. Expected 1 to 2 characters");
        }
        if (lineSeparator.length > 2) {
            throw new IllegalArgumentException("Invalid line separator. Up to 2 characters are expected. Got " + lineSeparator.length + " characters.");
        }
    }
}
